<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="date" label="日期" width="180"> </el-table-column>
      <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
      <el-table-column prop="phone" label="电话"> </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="tableData.length"
      :page-size="pagesize"
      :current-page="pagenumber"
      @current-change="Change"
    >
    </el-pagination>
  </div>
</template>

<script>
import json from "../../public/shopList.json";
export default {
  data() {
    return {
      tableData: [],
      pagesize: 10,
      pagenumber: 1,
    };
  },
  mounted() {
    console.log(json);
    json.forEach((item) => {
      console.log(item);
      var obj = {
        date: new Date().toLocaleString(),
        name: item.name,
        phone: item.phone,
      };
      this.tableData.push(obj);
    });
  },
  methods: {
    Change(val) {
      console.log(val);
      this.pagenumber = val;
    },
  },
  computed: {
    tableData: function () {
      return this.tableData.slice(
        this.pagesize * this.pagenumber - 1,
        this.pagesize * this.pagenumber
      );
    },
  },
};
</script>

<style>
</style>